{% extends 'baseh.html' %}
{% load static %}
{% block title %}
    {{ author_name }}的发布
{% endblock %}

{% block content %}
    <div class="container">
        <div class="center-block text-center">
            <h1 style="font-size:35px;font-family: 华文新魏,sans-serif;margin-top: 20px;margin-bottom: 15px"><span id="authorName">{{ author_name }}</span>的文章发布</h1>
        </div>
    <div class="bp3-collapse-body" style="margin-right:0;margin-left:0;margin-top: 20px">
        <div class="InputForm" style="display: flex;max-height:34px;margin: 8px">
            <div class="form-group">
                <label style="padding: 0;margin: 0">
                    <input type="text" class="form-control" placeholder="输入您的内容" style="width: 320px">
                </label>
            </div>

            <button type="button" class="btn btn-default" id="search">搜索</button>
            <button class="btn btn-primary" style="margin-right: 20px;margin-left: 20px"><a href="{% url 'article:article_post' %}" style="text-decoration:None;color:white">发布文章</a></button>
        </div>

        <table class="table table-hover">
        <tr id="baseRow">
            <th style="font-size: medium">序号</th>
            <th style="font-size: medium">文章标题</th>
            <th style="font-size: medium">栏目</th>
            <th style="font-size: medium">发表时间/修改时间</th>
            <th style="font-size: medium">操作</th>
        </tr>
        </table>
    </div>
    </div>
{% endblock %}
{% block jsFiles %}
    <script type="text/javascript">
    function getInfo(u_id,tag){
        $.ajax({
             url:'/article/user-articles/',
             type: "POST",
             dataType:'JSON',
             data:{'u_id':u_id,'detail':tag},
             success: function(resp){
                 // 异步加载新的内容
                 var prevRow = $('#baseRow');
                 for(var i=0;i<resp.data.length;i++){
                     var td1 = '<td>'+(i+1)+'</td>';
                     var td2 = '<td><a href="{% url 'article:show_article' %}?slug='+resp.data[i].slug+'&a_id='+resp.data[i].id+'">'+resp.data[i].title+'</td>';
                     var td3 = '<td><a href="{% url 'article:show_column_article' %}?c_name='+resp.data[i].c_name+'">'+resp.data[i].c_name+'</a></td>';
                     var td4 = '<td>'+resp.data[i].updated+'</td>';
                     var td5 = '<td> <a name="edit" href="javascript:" onclick="edit_column(this,'+resp.data[i].id+')"> <span class="glyphicon glyphicon-pencil"></span> </a> <a name="delete" href="javascript:" onclick="del_column(this,'+resp.data[i].id+')"> <span class="glyphicon glyphicon-trash" style="margin-left:20px; "></span> </a> </td>';
                     prevRow.after('<tr class="item">'+td1+td2+td3+td4+td5+'</tr>');
                     prevRow = prevRow.next();
                 }
             },
             error:function (){
                 alert('请求失败！');
            }
         });
    }
    var u_id = {{ author_id }};
    var tag = NaN;
    $(document).ready(function (){
        getInfo(u_id,tag);
    })
    $('#search').click(function (){
        tag = $('input').val();
        $('.item', 'table').each(function(){
            $(this).remove();
        });
        getInfo(u_id,tag);
    })

  $('input').bind('keypress',function(event){
         if(event.keyCode == "13"){
             $("#search").click();
         }
     });
    </script>
{% endblock %}